<?php

class DocPhotosAction extends Action {
  private $_dev = 0;
  function _initialize() {
    $this->_dev = C("DEV_FLAG");
    $this->assign("istp", 1);//circle-header2中有TP和PHPWIND都用到，加上这个参数进行区别
  }

  public function index() {
    $m = M();
    $sql = "select * from pw_cnphoto where ifthumb = 1 order by uptime limit 0,4";
    $list = $m->query($sql);
    foreach ($list as $k => $l) {
      $path = $l['path'];
      $arr = explode('.', $path);
      $str = $arr[0];
      $n = explode('/', $str);
      $name = $n[count($n)-1];
      $sname = "s_".$name;
      $list[$k]['spath'] = str_replace($name, $sname, $path);
    }
    $photosUrl = "/pw8/attachment/";
    //1-挂图，2-标志，3-作业现场
    $lbid = array();
    for ($i = 1; $i < 4; $i++) {
      $sql = "select t1.aid,t1.pid,t1.path 
        from pw_cnphoto t1
        left join pw_cnalbum t2 on (t1.aid = t2.aid)
        where t2.lbid = $i order by t1.uptime limit 0,6";
      $lbid[$i] = $m->query($sql);
    }
    foreach ($lbid as $k => $l) {
      foreach($l as $i => $li){
        $lbid[$k][$i]['path'] = $this->getAlbumCover($li['path']);
      }
    }
    $this->assign('lbidsName', array(1=>'挂图',2=>'标志',3=>'作业现场'));
    $this->assign('lbids', $lbid);
    $this->assign('purl', $photosUrl);
    $this->assign("newPhotos",$list);
    $this->display();
  }


  public function getAlbumCover( $path ) {
    $pathArr = explode('/', $path);
    $pathArrLen = count($pathArr);
    $pathArr[$pathArrLen - 1] = "s_" . $pathArr[$pathArrLen - 1];
    return implode('/', $pathArr);
  }


}
?>
